package tss.datastore.meta;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import tss.datastore.ValueType;

public class AttributeDefinition implements Externalizable {

    private String name;
    private ValueType type;

    public AttributeDefinition(String name, ValueType type) {
        this.name = name;
        this.type = type;
    }
    
    public AttributeDefinition() {
        
    }
    
    String getName() {
        return name;
    }

    @Override
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        this.name = (String) in.readObject();
        this.type = (ValueType) in.readObject();
        
    }

    @Override
    public void writeExternal(ObjectOutput out) throws IOException {
        out.writeObject(name);
        out.writeObject(type);        
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof AttributeDefinition) {
            AttributeDefinition other = (AttributeDefinition) obj;
            return this.name.equals(other.name) && this.type.equals(other.type);
        } else {
            return false;
        }        
    }
    
    @Override
    public int hashCode() {
        return 17 * name.hashCode() + type.hashCode();
    }    

}
